package com.wushijia.java8.stream;

import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Random;
import java.util.stream.IntStream;

/**
 * @author Benjamin Winterberg
 */
public class Streams13 {

  public static void main(String[] args) {
    SecureRandom secureRandom = new SecureRandom(new byte[]{1, 3, 3, 7});
    int[] randoms = IntStream.generate(secureRandom::nextInt)
        .filter(n -> n > 0)
        .limit(10)
        .toArray();
    System.out.println(Arrays.toString(randoms));

    int[] nums = IntStream.iterate(1, n -> n * 2)
        .limit(11)
        .toArray();
    System.out.println(Arrays.toString(nums));

    Random random = new Random();
    IntStream intStream = random.ints(10);
    System.out.println(Arrays.toString(intStream.limit(6).toArray()));
    //单个管道流只能输出一次，不可重复使用，所以下面这行报错
    intStream.limit(6).forEach(System.out::print);

  }
}
